

//————————————————————————————————————————————————合同审核————————————————————————————
$('.tableData').delegate(".documentAudit","click",function(){
	var documentId = $(this).parent().parent().find("td[class=documentId]").text()
		layer.open({
			type: 2,
			title: ['合同审核','background-color:#6d6e72; color:#fff;font-size:14px;'],
			shadeClose: true,
			shade: [0.9,'#cfcfcf'],
			area: ['98%', '98%'],  
			content: ['../ak/documentAudit.html?documentId='+documentId],// iframe的url，no代表不显示滚动条
			end:function(){
				getAjax();
			}
				
		});
})
//_________________________________________________________________________________查询按钮
	$("#query").click(function(){
		$(".page").val("1")
		getAjax()
	})

	
//————————————————————————————————————————————————合同详情————————————————————————————
$('.tableData').delegate(".detail","click",function(){
	var documentId = $(this).text();
	var documentStatus = $(this).parent().parent().find("td[class=documentStatus]").text();	
		layer.open({
			type: 2,
			title: ['合同详情','background-color:#6d6e72; color:#fff;font-size:14px;'],
			shadeClose: true,
			shade: [0.9,'#cfcfcf'],
			area: ['100%', '100%'],  
			content: ['../ak/documentQueryDetail.html?documentId='+documentId+"&documentStatus="+documentStatus],// iframe的url，no代表不显示滚动条
			end:function(){
				getAjax();
			}
				
		});
})
//————————————————————————————————————————————————合同中止————————————————————————————
$('.tableData').delegate(".documentStop","click",function(){
	var documentId = $(this).parent().parent().find("td[class=documentId]").text()
	layer.open({
			type: 2,
			title: ['合同中止','background-color:#6d6e72; color:#fff;font-size:14px;'],
			shadeClose: true,
			shade: [0.9,'#cfcfcf'],
			area: ['300px', '200px'],  
			content: ['../ak/documentStop.html?documentId='+documentId],// iframe的url，no代表不显示滚动条
			end:function(){
				getAjax();
			}
				
		});	
	
	
})

//————————————————————————————————————————————————合同取消————————————————————————————
$('.tableData').delegate(".documentCancle","click",function(){
	var documentId = $(this).parent().parent().find("td[class=documentId]").text()
	//询问框
	layer.confirm('确认取消该合同？', {
			title:['温馨提示','background-color:#6d6e72;color:#fff;font-size:14px;'],
			shade: [0.9,'#cfcfcf'],
		   	btn: ['确定','取消'] //按钮
		}, function(){
			layer.msg('取消中...', {icon: 16,shade: 0.01});
			$.ajax({
				type:"post",
				url:"../contract/"+documentId+"/cancel?trigger=pss",
				async:false,
				dataType:"json",
				success:function(data){
					console.log(data)
					if(data.status=="1001"){
						layer.msg('已取消', {icon: 1,time:1000},function(){
							getAjax();
						});
					}else{
						layer.msg('合同取消失败'+data.message, {icon: 2});
					}
				}			
			});		
			
		}, function(){
			
		});	
})
//____________________________________________出发到达机场条件互换________________
			$(".exchangeAirportCode").click(function(){
				var exchangeVar = $(".queryDep").val();
				$(".queryDep").val($(".queryArr").val());
				$(".queryArr").val(exchangeVar);
			})
			
//_______________________________________________页面渲染____________________________________
	
	var totalAmount
	var totalPage
	var nowPage
	function getAjax(){
		var id = $(".documentNo").val();
		if(/\((.)+?\)/.test($(".dep").val())){//获取出发机场三字码
			var departureAirport = $(".dep").val().slice(-5).split("(")[1].split(")")[0];
		}else{
			var departureAirport = $(".dep").val()
		}
		if(/\((.)+?\)/.test($(".arr").val())){//获取到达机场三字码
			var arriveAirport = $(".arr").val().slice(-5).split("(")[1].split(")")[0];
		}else{
			var arriveAirport = $(".arr").val()
		}
		//var departureAirport = $(".hiddeDepInput").text();
		//var arriveAirport = $(".hiddeArrInput").text();
		var status = $(".downBox").val();
		var pageNum = $(".page").val();
		var pageSize = $(".pageSize").val();
		layer.load();
		$.get("../contract/find?id="+id+"&departureAirport="+departureAirport+"&arriveAirport="+arriveAirport+"&status="+status+"&pageNum="+pageNum+"&pageSize="+pageSize+"&temp="+Math.random(),function(data){
			data = JSON.parse(data);
			layer.closeAll('loading');
			totalAmount = data.data.total
			totalPage = data.data.pages
			nowPage = data.data.pageNum
			//共多少条
			$(".totalAmount").text(totalAmount)
			//共多少页
			$(".totalPage").text(totalPage)
			//第几页
			$(".nowPage").text(nowPage)
			//每次经行请求时清空页面原有数据
			$(".clear").empty()	
			var str = "";
		
			for(var i=0;i<data.data.list.length;i++){
				var doStr="";
				if((data.data.list[i].status=="1")&&($(".cancel").val()=="1")){
					doStr = "<span title='取消' class='documentCancle iconfont'>&#xe611;</span>"
				}
				if((data.data.list[i].status=="2")&&($(".cancel").val()=="1")){
					doStr = "<span title='取消' class='documentCancle iconfont'>&#xe611;</span>"
				}
			
				if((data.data.list[i].status=="4")&&($(".breakoff").val()=="1")){
					doStr = "<span title='中止' class='documentStop iconfont'>&#xe688;</span>"
				}
			
				str+=/*"<tr class='NumberTr'>"+
						"<td colspan=10 class=con><span></span>合同号 : <span class='documentId'>"+data.data.list[i].id+"&nbsp;&nbsp;&nbsp;&nbsp;</span>产品号 : <span>"+data.data.list[i].productId+"</span></td>"+
						"<td class='fontCol detail'>合同详情</td>"+
					"</tr>"+*/
					"<tr>"+
						"<td class='documentId'><span class='detail'>"+data.data.list[i].id+"<span></td>"+
						"<td class=blue_size>"+data.data.list[i].customerName+"</td>"+
						"<td>"+commomFun.cabinStatusStr(data.data.list[i].seatClass)+"</td>"+
						"<td>"+data.data.list[i].createTime+"</td>"+
						"<td>"+commomFun.documentTypeStr(data.data.list[i].status)+"</td>"+
						"<td style='display:none' class='documentStatus'>"+data.data.list[i].status+"</td>"+
						/*"<td>"+data.data.list[i].legs+"</td>"+
						"<td class=blue_size>"+data.data.list[i].customerName+"</td>"+
						"<td>"+data.data.list[i].seatClass+"</td>"+
						"<td class=red_size>"+data.data.list[i].price+"</td>"+
						"<td>"+data.data.list[i].blockSeatAmount+"</td>"+
						"<td>"+data.data.list[i].startDate+"</td>"+
						"<td>"+data.data.list[i].endDate+"</td>"+
						"<td>"+data.data.list[i].createUserName+"</td>"+
						"<td>"+data.data.list[i].createTime+"</td>"+
						"<td>"+commomFun.documentTypeStr(data.data.list[i].status)+"</td>"+*/
						"<td>"+doStr+"</td>"+
					"</tr>"
			}
			$(".clear").append(str)
		})
	}
//________________________________________表头固定____________________________________________
	$("#dataTable").freezeHeader();
//________________________________________分页__________________________________
	$(".Pagination").load("Pagination.html",function(){
		messageUrl()
	})
//____________________________________________________________________________机场联想
var autocompleteData=[];
$.ajax({
	type:"get",
	url:"../Airapt?pageSize=100000&pageNum=1&temp="+Math.random(),
	dataType:"json",
	success:function(data){	
		autocompleteData = data.data.list; 
		$('.autocomplete').autocomplete({
		    lookup: autocompleteData,
		    autoSelectFirst:true,
		    onSelect: function (suggestion) {		   
		    }
		});
	}
})

$('.autocomplete').autocomplete({
    lookup: autocompleteData,
    autoSelectFirst:true,
    onSelect: function (suggestion) {		   
    }
});
//由消息提醒进入本页面
function messageUrl(){
	var mess = getHref().mess
	console.log(mess)
	if(mess=="documentAuditMessage"){
		$(".downBox").val("1");
		getAjax();
	}else{
		getAjax();
	}
}















